import type { StreamServer, ApiResponse, PageResponse, Camera,PageQuery,PtzControl,StreamPort } from '@/types'
import request from '@/utils/request'

// 服务器管理-获取所有的NVR
export function $getAllServer(type: number = 1): Promise<ApiResponse<StreamServer[]>> {
  return request.get<StreamServer[]>(`/serverController/getAllServer?type=${type}`)
}

// 服务器管理-获取NMC下面的流媒体服务器节点
export function $getAllSourceNodesByServerId(serverId: string): Promise<ApiResponse<SourceNode[]>> {
  return request.get<SourceNode[]>(`/serverController/getNMCSourceNodes?serverId=${serverId}`)
}

// 源节点类型定义
export interface SourceNode {
  sourceId: string
  sourceName: string
  ip: string
  port: string
  uuid: string
}

// 服务器管理-新增
export function $addServer(data: StreamServer): Promise<ApiResponse<StreamServer>> {
  return request.post<StreamServer>('/serverController/addServer', data)
}

// 服务器管理-编辑
export function $editServer(serverId: number, name: string): Promise<ApiResponse<StreamServer>> {
  return request.put<StreamServer>(`/serverController/editServerName?serverId=${serverId}&name=${name}`)
}

// 服务器管理-删除
export function $deleteServer(id: number): Promise<ApiResponse<void>> {
  return request.delete<void>(`/serverController/deleteServer?id=${id}`)
}


// 根据所在NVR获取摄像头列表
export function $getCameraListByNvrId(params: PageQuery & { nvrId: number }): Promise<ApiResponse<PageResponse<Camera[]>>> {
  return request.post<PageResponse<Camera[]>>(`/deviceController/getDeviceListByNvrByPage`,params)
}

// 获取流预览端口
export function $getStreamPreviewPort(): Promise<ApiResponse<StreamPort>> {
  return request.get<StreamPort>(`/serverController/getStreamPort`)
}

// 刷新NVR下的设备
export function $refreshDeviceListByServerId(serverId: number): Promise<ApiResponse<void>> {
  return request.get<void>(`/deviceController/refreshServerEqu?serverId=${serverId}`)
}

// 摄像机云台控制
export function $ptzControl(data: PtzControl): Promise<ApiResponse<void>> {
  return request.post<void>('/nvrControl/ptzControl', data)
}